class Solution {
public:
    int subarraySum(vector<int>& nums, int k)
    {
        int n = nums.size();
        vector<int> dp(n + 1, 0);

        for (int i = 1; i <= n; i++)
        {
            dp[i] = dp[i - 1] + nums[i - 1];
        }

        int sum = 0;
        for (int i = 1; i <= n; i++)
        {
            for (int j = 0; j < i; j++)
            {
                if (dp[i] - dp[j] == k)sum++;
            }
        }
        return sum;

    }
};